package o;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import androidx.annotation.NonNull;
import com.huawei.appgallery.assistantdock.base.cardkit.bean.BuoyBaseCardBean;
import com.huawei.appgallery.assistantdock.buoydock.card.bean.BuoyLanternItem;
import com.huawei.appgallery.assistantdock.gamemode.card.BuoyBaseEnterCard;
import com.huawei.appgallery.assistantdock.gamemode.card.BuoyLanternEnterCardBuoy;
import com.huawei.appgallery.foundation.ui.framework.cardkit.bean.CardBean;
import com.huawei.gamebox.plugin.gameservice.bean.GameInfo;
import java.util.ArrayList;
import java.util.List;
import o.bim.c;
import o.biu.a;

public class bgw extends bgz {
    private boolean ˊ;
    private LinearLayout ˎ;
    private List<a> ˏ = new ArrayList();
    private List<String> ॱ = new ArrayList();

    public void ॱ(Bundle bundle) {
        super.ॱ(bundle);
    }

    private GameInfo ˎ() {
        fae ˏ = fam.ॱ().ˏ();
        if (ˏ == null) {
            return null;
        }
        return ˏ.getGameInfo();
    }

    public void ˏ() {
        this.ˊ = ॱ();
        GameInfo ˎ = ˎ();
        if (ˎ != null) {
            bim.ॱ(ˉ(), ˎ, new c(this) {
                final /* synthetic */ bgw ˏ;

                {
                    this.ˏ = r1;
                }

                public void ॱ(List<String> list) {
                    if (list != null && !this.ˏ.ॱ((List) list)) {
                        Logger.ˏ("DockSegment", "not same dock list, need to refresh");
                        this.ˏ.ॱ = list;
                        this.ˏ.ʽ();
                    }
                }
            }, this.ˊ);
        }
        ʽ();
    }

    private boolean ॱ(@NonNull List<String> list) {
        if (this.ॱ != null && list.containsAll(this.ॱ) && this.ॱ.containsAll(list)) {
            return true;
        }
        return false;
    }

    public View ˋॱ() {
        super.ˋॱ();
        if (ˉ() == null) {
            Logger.e("DockSegment", "createView, getContext() == null");
            return null;
        }
        if (Logger.ˎ()) {
            Logger.ˎ("DockSegment", "onCreateView");
        }
        this.ˊ = ॱ();
        this.ˎ = (LinearLayout) LayoutInflater.from(ˉ()).inflate(beo$j.ˋ, null);
        return this.ˎ;
    }

    public void onResume() {
        super.onResume();
        ˏ();
    }

    private boolean ॱ() {
        return ezs.ˏ().ˋ(ˎ()) == null;
    }

    private void ʽ() {
        boolean z = false;
        if (this.ˎ == null) {
            Logger.e("DockSegment", "bindCards error, rootView is null.");
            return;
        }
        this.ॱ = bih.ॱ(ˉ(), ˎ(), this.ˊ);
        this.ˏ = bih.ˊ(ˎ(), this.ˊ);
        this.ˎ.removeAllViews();
        bid o_bid = new bid(this.ॱᐝ);
        int ˋ = ˋ(this.ॱ, 2, false, o_bid);
        int ˋ2 = ˋ(this.ˏ, 2, ˋ > 0, o_bid);
        List ˏ = bih.ˏ(ˎ());
        if (!CollectCheck.isEmpty(ˏ)) {
            BuoyLanternItem buoyLanternItem = (BuoyLanternItem) ˏ.get(0);
            BuoyBaseEnterCard buoyLanternEnterCardBuoy = new BuoyLanternEnterCardBuoy(this.ॱᐝ);
            LayoutParams layoutParams = new LayoutParams(-2, -2);
            layoutParams.gravity = 17;
            if (ˋ > 0 || ˋ2 > 0) {
                z = true;
            }
            ॱ(buoyLanternEnterCardBuoy, buoyLanternItem, layoutParams, z);
        }
        this.ˎ.invalidate();
    }

    private int ˋ(List list, int i, boolean z, bid o_bid) {
        if (list == null) {
            Logger.ˎ("DockSegment", "bindEnterCard: bindEnterCard");
            return 0;
        }
        int i2 = 0;
        int i3 = 0;
        while (i2 < list.size() && i3 < i) {
            boolean z2;
            BuoyBaseEnterCard ˊ = o_bid.ˊ(list.get(i2), false, this.ˊ, "DOCK");
            LayoutParams layoutParams = new LayoutParams(-2, -2);
            layoutParams.gravity = 17;
            if (i2 >= 1) {
                layoutParams.topMargin = (int) this.ॱᐝ.getResources().getDimension(beo$a.ˎ);
            }
            CardBean buoyBaseCardBean = new BuoyBaseCardBean();
            if (z && i2 == 0) {
                z2 = true;
            } else {
                z2 = false;
            }
            if (ॱ(ˊ, buoyBaseCardBean, layoutParams, z2)) {
                i3++;
            }
            i2++;
        }
        return i3;
    }

    private void ॱॱ() {
        if (this.ˎ == null) {
            Logger.e("DockSegment", "addDivider error, rootView is null.");
            return;
        }
        View view = new View(this.ॱᐝ);
        view.setBackgroundColor(this.ॱᐝ.getResources().getColor(beo$b.ˏ));
        ViewGroup.LayoutParams layoutParams = new LayoutParams(-1, 1);
        layoutParams.topMargin = (int) this.ॱᐝ.getResources().getDimension(beo$a.ˏ);
        layoutParams.bottomMargin = (int) this.ॱᐝ.getResources().getDimension(beo$a.ˏ);
        this.ˎ.addView(view, layoutParams);
    }

    private boolean ॱ(BuoyBaseEnterCard buoyBaseEnterCard, CardBean cardBean, LayoutParams layoutParams, boolean z) {
        if (this.ˎ == null) {
            Logger.e("DockSegment", "layoutEnterCard error, rootView = null");
            return false;
        } else if (buoyBaseEnterCard == null) {
            Logger.ˋ("DockSegment", "enterCard == null, not add card");
            return false;
        } else {
            if (z) {
                ॱॱ();
            }
            View inflate = LayoutInflater.from(ˉ()).inflate(beo$j.ʻ, this.ˎ, false);
            buoyBaseEnterCard.ˏ(inflate);
            buoyBaseEnterCard.ˏ(cardBean);
            inflate.findViewById(beo$e.ॱͺ).setVisibility(8);
            this.ˎ.addView(inflate, layoutParams);
            return true;
        }
    }
}
